package org.ywf.framework.factor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.FactoryBean;
import org.ywf.framework.proxy.ConsumerHandler;

import java.lang.reflect.Proxy;

@Slf4j
public class ProxyClientFactorBean implements FactoryBean {

    private final Class<?> interfaceType;

    public ProxyClientFactorBean(Class<?> interfaceType) {
        this.interfaceType = interfaceType;
    }

    @Override
    public Object getObject() throws Exception {
        log.info("生成{}类型代理类[{}]的代理Bean对象...",interfaceType.isInterface()==true?"接口":"类",interfaceType.getSimpleName());
        return Proxy.newProxyInstance(ProxyClientFactorBean.class.getClassLoader(), new Class[]{interfaceType}, new ConsumerHandler());
    }

    @Override
    public Class<?> getObjectType() {
        return interfaceType;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }
}
